﻿Imports System.Configuration
Imports System.Xml

Public Class RuleConfiguration
    Inherits ConfigurationSection

    Private Shared _Settings As RuleConfiguration = CType(ConfigurationManager.GetSection("RuleConfiguration"), RuleConfiguration)

    Public Shared ReadOnly Property Settings() As RuleConfiguration
        Get
            Return _Settings
        End Get
    End Property

    Private _Test As String

    <ConfigurationProperty("test")> _
    Public ReadOnly Property Test() As String
        Get
            Return CType(Me("test"), String)
        End Get
    End Property

End Class



'Public Class RuleSetHandler
'    Implements IConfigurationSectionHandler

'    Public Function Create( _
'    ByVal parent As Object, ByVal configContext As Object, ByVal section As System.Xml.XmlNode) _
'    As Object Implements System.Configuration.IConfigurationSectionHandler.Create

'        ' Creates the configuration object that this method will return.
'        ' This can be a custom configuration class.
'        ' In this example, we use a System.Collections.Hashtable.
'        Dim myConfigObject As New RuleSet(Of String)

'        ' Gets any attributes for this section element.
'        'Dim myAttribs As New Hashtable
'        'For Each attrib As XmlAttribute In section.Attributes
'        '    If XmlNodeType.Attribute = attrib.NodeType Then
'        '        myAttribs.Add(attrib.Name, attrib.Value)
'        '    End If
'        'Next

'        ' Puts the section name and attributes as the first config object item.
'        myConfigObject.Add(section.Name, myAttribs)

'        ' Gets the child element names and attributes.
'        For Each child As XmlNode In section.ChildNodes
'            If XmlNodeType.Element = child.NodeType Then
'                Dim myChildAttribs As New Hashtable

'                For Each childAttrib As XmlAttribute In child.Attributes
'                    If XmlNodeType.Attribute = childAttrib.NodeType Then
'                        myChildAttribs.Add(childAttrib.Name, childAttrib.Value)
'                    End If
'                Next
'                myConfigObject.Add(child.Name, myChildAttribs)
'            End If
'        Next

'        Return (myConfigObject)

'    End Function

'End Class

